import 'package:flutter/material.dart';
import './login.dart';
import 'package:provide/provide.dart';
import '../provide/person.dart';
import 'package:fluttertoast/fluttertoast.dart';
import './Setting.dart';
import './pwdUpd.dart';

class DrawerPage extends StatelessWidget {

  DrawerPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: ListView(
        children: <Widget>[
          UserAccountsDrawerHeader(
            currentAccountPicture: Provide<PersonnalProvider>(
              builder: (context,child,val){
                return ClipOval(
                  child: Image.network(val.avatar),
                );
              },
            ),
            accountName: Provide<PersonnalProvider>(
              builder: (context,child,val){
                return Text(
                  '欢迎您，${val.username}'
                );
              },
            ),
            accountEmail: Text('1650024814@qq.com'),
          ),
          ListTile(
            onTap: (){
              Navigator.push(context, MaterialPageRoute(
                builder: (context){
                  return SettingPage();
                }
              ));
            },
            leading: Icon(Icons.settings),
            title: Text('设置'),
            trailing: Icon(Icons.chevron_right),
          ),
          ListTile(
            onTap: (){
              Fluttertoast.showToast(
                msg: "这个没写别点了",
                toastLength: Toast.LENGTH_SHORT,
                gravity: ToastGravity.BOTTOM,
                timeInSecForIos: 1,
                backgroundColor: Theme.of(context).primaryColor,
                textColor: Colors.white,
                fontSize: 16.0
              );
            },
            leading: Icon(Icons.favorite),
            title: Text('我的收藏'),
            trailing: Icon(Icons.chevron_right),
          ),
          ListTile(
            onTap: (){
              Fluttertoast.showToast(
                msg: "这个没写别点了",
                toastLength: Toast.LENGTH_SHORT,
                gravity: ToastGravity.BOTTOM,
                timeInSecForIos: 1,
                backgroundColor: Theme.of(context).primaryColor,
                textColor: Colors.white,
                fontSize: 16.0
              );
            },
            leading: Icon(Icons.share),
            title: Text('分享这个APP'),
            trailing: Icon(Icons.chevron_right),
          ),
          Provide<PersonnalProvider>(
            builder: (context,child,val){
              return val.username == '游客'?
                      ListTile(
                        onTap: (){
                          Navigator.push(context, MaterialPageRoute(
                            builder: (context){
                              return LoginPage();
                            }
                          ));
                        },
                        leading: Icon(Icons.group),
                        title: Text('登录'),
                        trailing: Icon(Icons.chevron_right),
                      ):
                      ListTile(
                        onTap: (){
                          // 注销操作
                          val.out();
                          Navigator.pop(context);
                        },
                        leading: Icon(Icons.person_add),
                        title: Text('注销'),
                        trailing: Icon(Icons.chevron_right),
                      );

            },
          ),
          Provide<PersonnalProvider>(
            builder: (context,child,val){
              return val.username != '游客'?
                      ListTile(
                        onTap: (){
                          Navigator.push(context, MaterialPageRoute(
                            builder: (context){
                              return PwdUpdPage();
                            }
                          ));
                        },
                        leading: Icon(Icons.keyboard),
                        title: Text('修改密码'),
                        trailing: Icon(Icons.chevron_right),
                      ): Text('');

            },
          ),
        ],
      )
    );
  }
}